<?php

load_helper('html');
assets::instance() ->css( "list" );

$header = '';
foreach( $_header as $row )
{
	$header .= '<tr>';
	foreach( $row as $cell )
	{
		$th = array( );
		foreach( array( 'class', 'title', 'width' ) as $k )
			if( isset( $cell[$k] ) )
				$th[$k] = $cell[$k];
		
		$th['title'] = isset( $th['title'] ) ? $th['title'] : $cell['name'];
		
		if( @$cell['columns'] > 1 )
			$th['colspan'] = $cell['columns'];
		if( @$cell['rows'] > 1 )
			$th['rowspan'] = $cell['rows'];
		
		$th['html'] = $cell['name'];
		
		if( @$cell['href'] )
			$th['html'] = sprintf( '<a href="%s" title="%s">%s</a>', html_escape( $cell['href'] ), html_escape( $th['title'] ), $th['html'] );
		
		$header .= html_element( 'th', $th );
	}
	$header .= '</tr>';
}

if( !isset( $id ) )
	$id = 'tablelist_'.rand( 100, 999 );

$table_props = 'cellpadding="0" cellspacing="0"';
foreach( array( 'id', 'class', 'width' ) as $k )
	if( isset( $$k ) )
		$table_props .= sprintf( ' %s="%s"', $k, html_escape( $$k ) );

?>
<table <?php echo $table_props; ?>>
<?php if( $headtype & 1 || isset($sky) ): ?>
<thead>
	<?php if( isset($sky) ): ?>
	<tr class="tablesky"><th colspan="<?php echo $_columns; ?>"><?php echo $sky; ?></th></tr>
	<?php endif; ?>
	<?php if( $headtype & 1 ) echo $header; ?>
</thead>
<?php endif; ?>
<tbody>
<?php
foreach( $from as $rowkey => $row ):
$rowid = $id.'_'.$rowkey;
?>
<tr class="<?=html_cycle("odd,even")?>" id="<?=$rowid?>">
	<?php $i = 0; foreach( $row as $k => $v ): $cellid = $rowid.'_'.$k; ?>
		<?php if( $i < $_columns ): ?><td id="<?=$cellid?>"><?=$v?></td><?php endif; ?>
	<?php $i++; endforeach; ?>
	<?php for( ; $i<$_columns; $i++ ) echo '<td>'.$spacer.'</td>'; ?>
</tr>
<?php
endforeach;
?>
</tbody>
<?php if( $headtype & 2 ) echo '<tfoot>'.$header.'</tfoot>'; ?>
</table>

